#include<iostream>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;i++)
int arr[505][505], store[505][505];

void L(int x, int y, int r){
    f(i,x-r,x+r)
        f(j,y-r,y+r){
            int x_dev=i-x, y_dev=j-y;
            store[i][j]=arr[x+y_dev][y-x_dev];
        }
}
void R(int x, int y, int r){
    f(i,x-r,x+r)
        f(j,y-r,y+r){
            int x_dev=i-x, y_dev=j-y;
            store[i][j]=arr[x-y_dev][y+x_dev];
        }
}
void write(int x,int y,int r){
    f(i,x-r,x+r)
        f(j,y-r,y+r){
            arr[i][j]=store[i][j];
        }
}

int main(){
    int n,m,cnt=1;
    cin>>n>>m;
    f(i,1,n)
        f(j,1,n){
            arr[i][j]=cnt;
            ++cnt;
        }

    // f(i,1,n){
    //     f(j,1,n){
    //         cout<<arr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<endl<<endl;

    f(u,1,m){
        int x,y,r,z;
        cin>>x>>y>>r>>z;
        //--x;--y;
        if(z==0)
            R(x,y,r);
        else{
            L(x,y,r);
        }
        write(x,y,r);
        
        // cout<<"x:"<<x<<" y:"<<y<<" r:"<<r<<" z:"<<z<<endl;
        // f(i,1,n){
        //     f(j,1,n){
        //         cout<<arr[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        // cout<<endl<<endl;
    }
    //return 0;
    f(i,1,n){
        f(j,1,n){
            cout<<arr[i][j]<<" ";
        }
        cout<<endl;
    }
}